<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>LCV Framework: log.c Quellcode</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Erzeugt von Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Hauptseite</span></a></li>
    <li><a href="classes.html"><span>Datenstrukturen</span></a></li>
    <li class="current"><a href="files.html"><span>Dateien</span></a></li>
  </ul>
</div>
<h1>log.c</h1><a href="log_8c.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="lcv-config_8h.html" title="Enthält die allgemeinen Definitionen des LCV Frameworks.">lcv-config.h</a>"</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include "<a class="code" href="log_8h.html" title="Ein Werkzeug zur Protokollierung.">log.h</a>"</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="keywordtype">void</span> <a class="code" href="log_8c.html#9e7ce688d4671076d46d6d8eab6251d8">lcv_first_log_entry</a>();
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="comment">/*</span>
<a name="l00018"></a>00018 <span class="comment"> * Logging aktivieren, deaktivieren</span>
<a name="l00019"></a>00019 <span class="comment"> */</span>
<a name="l00020"></a><a class="code" href="log_8c.html#c432b3f7381f4b4ebdc9f20df2eb537a">00020</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="log_8c.html#c432b3f7381f4b4ebdc9f20df2eb537a">logging_is_enabled</a> = <a class="code" href="lcv-config_8h.html#a8cecfc5c5c054d2875c03e77b7be15d" title="Booleans.">TRUE</a>;
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="comment">/*</span>
<a name="l00023"></a>00023 <span class="comment"> * Neue Logdatei</span>
<a name="l00024"></a>00024 <span class="comment"> */</span>
<a name="l00025"></a><a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">00025</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">first_log_entry</a> = <a class="code" href="lcv-config_8h.html#a8cecfc5c5c054d2875c03e77b7be15d" title="Booleans.">TRUE</a>;
<a name="l00026"></a>00026 
<a name="l00027"></a><a class="code" href="log_8h.html#e9c80c6a5fc3b1816d6131a8d7f21fba">00027</a> <span class="keywordtype">void</span> <a class="code" href="log_8c.html#e9c80c6a5fc3b1816d6131a8d7f21fba" title="Aktiviert, bzw.">lcv_logging</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> enable)
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029         <a class="code" href="log_8c.html#c432b3f7381f4b4ebdc9f20df2eb537a">logging_is_enabled</a> = enable;
<a name="l00030"></a>00030 }
<a name="l00031"></a>00031 
<a name="l00032"></a><a class="code" href="log_8h.html#64e28a98e670fc7cd88d040fe59c2f5d">00032</a> <span class="keywordtype">void</span> <a class="code" href="log_8c.html#64e28a98e670fc7cd88d040fe59c2f5d" title="Schreibt einen Eintrag in die Protokolldatei.">lcv_log</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * entry)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034         <span class="keywordflow">if</span> (<a class="code" href="log_8c.html#c432b3f7381f4b4ebdc9f20df2eb537a">logging_is_enabled</a>) {
<a name="l00035"></a>00035                 <span class="keywordflow">if</span> (<a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">first_log_entry</a>) {
<a name="l00036"></a>00036                         <a class="code" href="log_8c.html#9e7ce688d4671076d46d6d8eab6251d8">lcv_first_log_entry</a>();
<a name="l00037"></a>00037                         <a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">first_log_entry</a> = <a class="code" href="lcv-config_8h.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00038"></a>00038                 }
<a name="l00039"></a>00039                 
<a name="l00040"></a>00040                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> buffersize = 256;
<a name="l00041"></a>00041                 <span class="keywordtype">char</span> t_buffer[buffersize];
<a name="l00042"></a>00042                 time_t curtime;
<a name="l00043"></a>00043                 <span class="keyword">struct </span>tm *loctime;
<a name="l00044"></a>00044                              
<a name="l00045"></a>00045                 <span class="comment">/* Momentane Zeit holen */</span>
<a name="l00046"></a>00046                 curtime = time (NULL);
<a name="l00047"></a>00047                              
<a name="l00048"></a>00048                 <span class="comment">/* Konvertieren zur Lokalzeit */</span>
<a name="l00049"></a>00049                 loctime = localtime (&amp;curtime);
<a name="l00050"></a>00050                             
<a name="l00051"></a>00051                 <span class="comment">/* Format ändern */</span>
<a name="l00052"></a>00052                 strftime (t_buffer, buffersize, <span class="stringliteral">"%Y-%m-%d %H:%M:%S"</span>, loctime);  
<a name="l00053"></a>00053                 
<a name="l00054"></a>00054                 <span class="comment">/* Newlines des Eintrages löschen */</span>   
<a name="l00055"></a>00055                 <span class="keywordtype">char</span> corrected_entry[256]; 
<a name="l00056"></a>00056                 strcpy(corrected_entry, entry); 
<a name="l00057"></a>00057                 <span class="keywordtype">char</span> * newline;
<a name="l00058"></a>00058                 
<a name="l00059"></a>00059                 <span class="keywordflow">while</span> ((newline = strchr(corrected_entry, <span class="charliteral">'\n'</span>)) != NULL) {
<a name="l00060"></a>00060                         (*newline)      = <span class="charliteral">' '</span>;
<a name="l00061"></a>00061                 }
<a name="l00062"></a>00062                                                                         
<a name="l00063"></a>00063                 FILE* logfile = fopen(<a class="code" href="log-config_8h.html#6f6e0a7a87048fb100a02f5c9d8660d6" title="Dateiname des Logiles.">LOG_FILE_NAME</a>, <span class="stringliteral">"a"</span>);               
<a name="l00064"></a>00064                 fprintf(logfile, <span class="stringliteral">"%s - %s\n"</span>, t_buffer, corrected_entry);
<a name="l00065"></a>00065                 fclose(logfile);
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00069"></a><a class="code" href="log_8c.html#9e7ce688d4671076d46d6d8eab6251d8">00069</a> <span class="keywordtype">void</span> <a class="code" href="log_8c.html#9e7ce688d4671076d46d6d8eab6251d8">lcv_first_log_entry</a>()
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071         <span class="keywordflow">if</span> (<a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">first_log_entry</a>) {
<a name="l00072"></a>00072                 FILE* logfile = fopen(<a class="code" href="log-config_8h.html#6f6e0a7a87048fb100a02f5c9d8660d6" title="Dateiname des Logiles.">LOG_FILE_NAME</a>, <span class="stringliteral">"a"</span>);               
<a name="l00073"></a>00073                 fprintf(logfile, <span class="stringliteral">"/***************************************************************\n"</span>);
<a name="l00074"></a>00074                 fprintf(logfile, <span class="stringliteral">"* NEW PROGRAMM EXECUTION\n"</span>);
<a name="l00075"></a>00075                 fprintf(logfile, <span class="stringliteral">"***************************************************************/\n"</span>);
<a name="l00076"></a>00076                 fclose(logfile);
<a name="l00077"></a>00077                 
<a name="l00078"></a>00078                 <a class="code" href="log_8c.html#c3305ea1fd60509330467d69c3625d08">first_log_entry</a> = <a class="code" href="lcv-config_8h.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00079"></a>00079         }
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="log_8h.html#ff9ff7830b2121dcd8e64d7cc1252534">00082</a> <span class="keywordtype">void</span> <a class="code" href="log_8c.html#ff9ff7830b2121dcd8e64d7cc1252534" title="Schreibt einen Fehler-Eintrag in die Protokolldatei.">lcv_log_error</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * entry, <span class="keyword">const</span> <span class="keywordtype">char</span>* function)
<a name="l00083"></a>00083 {               
<a name="l00084"></a>00084         <span class="keywordtype">char</span> buffer[256];
<a name="l00085"></a>00085         sprintf(buffer, <span class="stringliteral">"Error in Function &gt;%s&lt;: %s"</span>, function, entry); 
<a name="l00086"></a>00086         <a class="code" href="log_8c.html#64e28a98e670fc7cd88d040fe59c2f5d" title="Schreibt einen Eintrag in die Protokolldatei.">lcv_log</a>(buffer);
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a><a class="code" href="log_8h.html#8478a914926d15bf375feb130ff51b3e">00089</a> <span class="keywordtype">void</span> <a class="code" href="log_8c.html#8478a914926d15bf375feb130ff51b3e" title="Schreibt einen Warnungs-Eintrag in die Protokoll-Datei.">lcv_log_warning</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* entry, <span class="keyword">const</span> <span class="keywordtype">char</span>* function)
<a name="l00090"></a>00090 {
<a name="l00091"></a>00091         <span class="keywordtype">char</span> buffer[256];
<a name="l00092"></a>00092         sprintf(buffer, <span class="stringliteral">"Warning in Function &gt;%s&lt;: %s"</span>, function, entry);       
<a name="l00093"></a>00093         <a class="code" href="log_8c.html#64e28a98e670fc7cd88d040fe59c2f5d" title="Schreibt einen Eintrag in die Protokolldatei.">lcv_log</a>(buffer);
<a name="l00094"></a>00094 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Erzeugt am Wed Dec 19 16:38:17 2007 für LCV Framework von&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>
